# -*-coding:utf-8 -*-
import pathlib

from third_api.yb import YBApi

from .. import config, utils


class XZBaseHandler(object):
    yb_api = YBApi()
    vin2vehicle_map = utils.bms_vehicle2gnss_vehicle_info()
    logger = utils.get_logger('xz-handlers')

    MEDIA_UPLOADS_PATH = config.MEDIA_UPLOADS_PATH

    WARNING_TYPE_MAP = {'100001': 2,   # '一级分神',
                        '100002': 2,   # '二级分神',
                        '100003': 35,  # '抽烟',
                        '100004': 36,  # '打电话',
                        '100005': 2,   # '打哈欠',
                        '100006': 37,  # '摄像头遮挡',
                        '100007': 38,  # '左顾右盼',
                        '100008': 39,  # '换人提醒',
                        '100009': 40,  # '驾驶超时',
                        '200001': 29,  # '前车碰撞',
                        '200002': 41,  # '车道偏移',
                        '200003': 42,  # '前车过近',
                        '200004': 43,  # '急刹车',
                        '200005': 44,  # '急减速',
                        '200006': 45,  # '急加速',
                        '200007': 46,  # '急转弯',
                        '200008': 47,  # '行人检测',
                        '200009': 0    # '超速行驶'
                        }

    def map2new_vehicle_id(self, old_vehicle_id):
        if old_vehicle_id in self.vin2vehicle_map:
            return self.vin2vehicle_map[old_vehicle_id]['vehicle_id']
        else:
            self.logger.error(f'old_vehicle_id={old_vehicle_id}找不出新vehicle_id')
            return None

    def map2new_terminal_id(self, old_vehicle_id):
        if old_vehicle_id in self.vin2vehicle_map:
            return self.vin2vehicle_map[old_vehicle_id]['terminal_id']
        else:
            self.logger.error(f'old_vehicle_id={old_vehicle_id}找不出新vehicle_id')
            return None
